﻿Module SevenZipTools
    Dim CursorLeft As Integer
    Dim CursorTop As Integer

    Private WithEvents SZ As SevenZip.SevenZipExtractor
    Public Sub Extract(Arch As String, Path As String)
        CursorTop = Console.CursorTop
        CursorLeft = Console.CursorLeft
        DrawProgresBar()

        If Environment.Is64BitProcess Then
            SevenZip.SevenZipExtractor.SetLibraryPath(AppPath & "\7z64.dll")
        Else
            SevenZip.SevenZipExtractor.SetLibraryPath(AppPath & "\7z32.dll")
        End If
        Try
            SZ = New SevenZip.SevenZipExtractor(Arch)

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Exit Sub
        End Try
        Try
            SZ.ExtractArchive(Path)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Exit Sub
        End Try
        Console.SetCursorPosition(0, 4)
    End Sub

    Private Sub SZ_Extracting(sender As Object, e As SevenZip.ProgressEventArgs) Handles SZ.Extracting
        UpdateProgresBar(e.PercentDone, ConsoleColor.green)
    End Sub

    Private Sub SZ_ExtractionFinished(sender As Object, e As EventArgs) Handles SZ.ExtractionFinished
        SetConsoleColors(ConsoleColor.grey)
    End Sub
End Module
